package com.chinatelecom.service.system.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinatelecom.common.domain.QueryRequest;
import com.chinatelecom.common.utils.SortUtil;
import com.chinatelecom.dao.system.SysAreaMapper;
import com.chinatelecom.entity.system.SysArea;
import com.chinatelecom.service.system.ISysAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author nobody
 */
@Service
public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysArea> implements ISysAreaService {

    /**
     * 查询所有地区
     **/
    public IPage<SysArea> getList(SysArea area, QueryRequest request) {
        try {
            LambdaQueryWrapper<SysArea> queryWrapper = new LambdaQueryWrapper<>();
            if (area.getPid() != null) {
                queryWrapper.eq(SysArea::getPid, area.getPid());
            }
            if (area.getLevel() != null) {
                queryWrapper.eq(SysArea::getLevel, area.getLevel());
            }
            if (StringUtils.isNotBlank(area.getName())) {
                queryWrapper.like(SysArea::getName, area.getName());
            }

            Page<SysArea> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.page(page, queryWrapper);
        } catch (Exception e) {
            log.error("获取行政区域列表失败", e);
            return null;
        }
    }


}
